package com.example.service.Impl;

import com.example.Dao.DownFileAutomatictory;
import com.example.Dao.IDemoRepository;
import com.example.Dao.MyFiletory;
import com.example.bean.DownFile;
import com.example.bean.Myfile;
import com.example.service.MyfileService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;

/**
 * Created by 殇 on 2022/8/14.
 */
@Service
public class MyfileServiceImpl implements MyfileService{

//    自动生成的数据操作方法
    @Autowired
    private IDemoRepository iDemoRepository;

    @Autowired
    DownFileAutomatictory downFileAutomatictory;

//    较复杂，认为完成的数据库操作方法
    @Autowired
    private MyFiletory myFiletory;


    @Override
    public List<Myfile> getAllByFilename(String filename) {
        return null;
    }

    @Override
    public void save(Myfile Myfile) {

        iDemoRepository.save(Myfile);

    }

    public void DownSave(DownFile downFile){
        downFileAutomatictory.save(downFile);
    }


    @Override
    public List<Myfile> getAll() {
        return (List<Myfile>)iDemoRepository.findAll();
    }


    @Override
    public PageInfo<Myfile> SelAllByName(Myfile myfile, Integer page, Integer limit) {
        PageInfo<Myfile> pageInfo = new PageInfo<>();

//        PageHelper.startPage(page,limit);
//        List<Myfile> myfiles = myFiletory.SelAllByName((DownFile) myfile);
//
//        pageInfo.setList(myfiles);
//
//        System.out.println("——SelAllByNamew——");
//
//        System.out.println(pageInfo.toString());
//
//        System.out.println(page + "--" + limit);
//
//        System.out.println(pageInfo.getSize());
//        pageInfo.setTotal(myFiletory.Total());

        return pageInfo;
    }

    public PageInfo<DownFile> SelDowunAllByName(DownFile downFile, Integer page, Integer limit) {
        PageInfo<DownFile> pageInfo = new PageInfo<>();

        PageHelper.startPage(page,limit);
        List<DownFile> downFiles = myFiletory.SelAllByName(downFile);

        pageInfo.setList(downFiles);

        System.out.println("——SelDownAllByNamew——");
        System.out.println(downFiles.size());
        System.out.println(pageInfo.toString());

        System.out.println(page + "--" + limit);

        System.out.println(pageInfo.getSize());
        pageInfo.setTotal(myFiletory.Total());

        return pageInfo;
    }


    public void DelDownFile(){
        downFileAutomatictory.deleteAll();
//        myFiletory.DelDownFile();
    }





}
